package rpc

import (
	"app.com/common.v1/tool"
	"app.com/rpc.v1/config"
	demo "app.com/rpc.v1/rpc/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
)

type Client struct {
	DemoClient demo.DemoClient
}

func NewClient() (*Client, error) {
	conn, err := grpc.Dial(config.AppConf.GrpcConf.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		tool.Error("grpc client 连接失败！" + err.Error())
		log.Fatal(err)
	}
	cli := &Client{}
	cli.DemoClient = demo.NewDemoClient(conn)
	return cli, nil
}
